package com.tc168.cp306.b06.adaptre;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tc168.cp306.b06.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

//todo 跟帖适配器
public class BijiAdapter extends RecyclerView.Adapter {


    private MyItemClickListener listener;
    /**
     * 类型1banner
     */
    public static final int ONETYPE = 0;


    private Context mcontext;
    private List<String> mdata;

    private LayoutInflater mLayoutInflater;
    private String imgUrl;

    private List<Integer> imgs;


    public BijiAdapter(Context mcontext, List<String> mdata) {
        this.mcontext = mcontext;
        this.mdata = mdata;
        mLayoutInflater = LayoutInflater.from(mcontext);
        imgs = new ArrayList<Integer>();
        imgs.add(R.mipmap.title_img0);
        imgs.add(R.mipmap.title_img1);
        imgs.add(R.mipmap.title_img2);
        imgs.add(R.mipmap.title_img3);
        imgs.add(R.mipmap.title_img4);
        imgs.add(R.mipmap.title_img5);
        imgs.add(R.mipmap.title_img6);
        imgs.add(R.mipmap.title_img7);
        imgs.add(R.mipmap.title_img8);
        imgs.add(R.mipmap.title_img9);
    }

    public interface MyItemClickListener {
        public void onItemClick(View view, int postion);
    }

    /**
     * 设置Item点击监听
     *
     * @param listener
     */
    public void setOnItemClickListener(MyItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemViewType(int position) {

        return ONETYPE;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ONETYPE) {
            return new OneViewHolder(mcontext, mLayoutInflater.inflate(R.layout.item_note, parent, false));
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        if (getItemViewType(position) == ONETYPE) {
            OneViewHolder oneViewHolder = (OneViewHolder) holder;

            oneViewHolder.titile.setText(mdata.get(position));

        }
    }

    @Override
    public int getItemCount() {
        return mdata.size();
    }


    class OneViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private final Context mContext;
        @BindView(R.id.image)
        ImageView answerIg;
        @BindView(R.id.tv)
        TextView titile;
        @BindView(R.id.ll)
        LinearLayout ll;

        public OneViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            ButterKnife.bind(this, itemView);

            ll.setOnClickListener(this);

        }


        @Override
        public void onClick(View view) {
            listener.onItemClick(view, getAdapterPosition());
        }
    }


}
